* Produces stylized facts table
* Jetson Leder-Luis
* False Claims Act paper

use FOIADataClean.dta, clear 

************************************************************************************
*** Stylized facts: All cases

* Number of cases
count 
local ncases = r(N)

*** How many SJ/Dismissals
count if sj == 1 
local nsettled = r(N)
local fracsettlements = `nsettled'/`ncases'
count if SJAmount == 0

** Number of interventions
count if intervened == 1 
local nintervened = r(N)
local fracintervened = `nintervened'/`ncases'


** Overlap of intervention and settlement
count if sj == 1 & intervened == 1 
local frac_settled_if_intervened = r(N)/`nintervened'
local frac_intervened_if_settled = r(N)/`nsettled'


*** Settlement amounts for settled cases
summarize SJAmount if SJAmount >0, detail
local sjmean = r(mean)
local sjmedian = r(p50)
local sjstd = r(sd)
local sjsum = r(sum)


*** Relator pay stats when nonzero
summarize RelatorShare if RelatorShare >0, detail
local relatormean = r(mean)
local relatormedian = r(p50)
local relatorstd = r(sd)
local relatorsum = r(sum)

*** Case length
summarize caselength if caselength >=0, detail
	* restrict to >0 to omit cases with poorly coded end dates (3 cases)
local caselengthmean = r(mean)
local caselenghtmedian = r(p50)
local caselengthstd = r(sd)

************************************************************************************
*** Stylized facts: Healthcare cases 
keep if inlist(PrimaryAgency, "HHS", "CMS", "FDA")

* Number of cases
count 
local ncases_HC = r(N)

*** How many SJ/Dismissals
count if sj == 1 
local nsettled_HC = r(N)
local fracsettlements_HC = `nsettled_HC'/`ncases_HC'

** Number of interventions
count if intervened == 1 
local nintervened_HC = r(N)
local fracintervened_HC = `nintervened_HC'/`ncases_HC'


** Overlap of intervention and settlement
count if sj == 1 & intervened == 1 
local frac_settled_if_intervened_HC = r(N)/`nintervened_HC'
local frac_intervened_if_settled_HC = r(N)/`nsettled_HC'


*** Settlement amounts for settled cases
summarize SJAmount if SJAmount >0, detail
local sjmean_HC = r(mean)
local sjmedian_HC = r(p50)
local sjstd_HC = r(sd)
local sjsum_HC = r(sum)


*** Relator pay stats when nonzero
summarize RelatorShare if RelatorShare >0, detail
local relatormean_HC = r(mean)
local relatormedian_HC = r(p50)
local relatorstd_HC = r(sd)
local relatorsum_HC = r(sum)

*** Case length
summarize caselength if caselength >=0, detail
	* restrict to >0 to omit cases with poorly coded end dates (3 cases)
local caselengthmean_HC = r(mean)
local caselenghtmedian_HC = r(p50)
local caselengthstd_HC = r(sd)


macro list 




********************************************************************************
**** Plot: HC cases, total cases and by settlement/dismissal by filing year 
use FOIADataClean.dta, clear 

** Filter to HC cases
keep if inlist(PrimaryAgency, "HHS", "CMS", "FDA")

* Settlements vs dismissals by year 
gen count = 1 
collapse (sum) count , by(sj filingyear)

gen countsj = count if sj == 1
gen countdismissal = count if sj == 0 

* Total by year 
bysort filingyear: egen counttot = total(count)

** Make into a panel 
collapse (min) countsj (min) countdismissal (max) counttot, by(filingyear)

* Label for plotting
label var countsj "Settlements or Judgements" 
label var countdismissal "Dismissals"
label var counttot "Total Cases"

* Plot and save
twoway line countsj countdismissal counttot filingyear, xtitle("Year of Filing") ytitle("# Cases") graphregion(color(white)) lpattern(dash longdash solid)
graph export "TimeTrend.pdf", replace


********************************************************************************
****  SJ by year 
use FOIADataClean.dta, clear 

keep if inlist(PrimaryAgency, "HHS", "CMS", "FDA")

gen SJyear = year(SJDateDismissalDate)
drop if SJyear > 2012 
collapse (sum) SJAmount, by(SJyear)


************************************************************************************
*** Cases by agency
use FOIADataClean.dta, clear 


tabulate PrimaryAgency